package com.yinhe.module.dfx.controller;

import com.yinhe.common.annotation.Log;
import com.yinhe.common.core.controller.BaseController;
import com.yinhe.common.core.domain.AjaxResult;
import com.yinhe.common.core.page.TableDataInfo;
import com.yinhe.common.enums.BusinessType;
import com.yinhe.common.utils.SecurityUtils;
import com.yinhe.common.utils.poi.ExcelUtil;
import com.yinhe.system.domain.YhInspection;
import com.yinhe.system.service.IYhInspectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 查铺记录Controller
 * 
 * @author yinhe
 * @date 2022-07-13
 */
@RestController
@RequestMapping("/dfx/inspection")
public class DfxInspectionController extends BaseController
{
    @Autowired
    private IYhInspectionService yhInspectionService;

    /**
     * 查询查铺记录列表
     */
    @PreAuthorize("@ss.hasPermi('dfx:inspection:list')")
    @GetMapping("/list")
    public TableDataInfo list(YhInspection yhInspection)
    {
        startPage();
        List<YhInspection> list = yhInspectionService.selectYhInspectionList(yhInspection);
        return getDataTable(list);
    }

    /**
     * 导出查铺记录列表
     */
    @PreAuthorize("@ss.hasPermi('dfx:inspection:export')")
    @Log(title = "查铺记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YhInspection yhInspection)
    {
        List<YhInspection> list = yhInspectionService.selectYhInspectionList(yhInspection);
        ExcelUtil<YhInspection> util = new ExcelUtil<YhInspection>(YhInspection.class);
        util.exportExcel(response, list, "查铺记录数据");
    }

    /**
     * 获取查铺记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('dfx:inspection:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(yhInspectionService.selectYhInspectionById(id));
    }

    /**
     * 新增查铺记录
     */
    @PreAuthorize("@ss.hasPermi('dfx:inspection:add')")
    @Log(title = "查铺记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YhInspection yhInspection)
    {
        yhInspection.setUserId(SecurityUtils.getLoginUser().getUserId());
        yhInspection.setDeptId(SecurityUtils.getLoginUser().getDeptId());

        return toAjax(yhInspectionService.insertYhInspection(yhInspection));
    }

    /**
     * 修改查铺记录
     */
    @PreAuthorize("@ss.hasPermi('dfx:inspection:edit')")
    @Log(title = "查铺记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YhInspection yhInspection)
    {
        return toAjax(yhInspectionService.updateYhInspection(yhInspection));
    }

    /**
     * 删除查铺记录
     */
    @PreAuthorize("@ss.hasPermi('dfx:inspection:remove')")
    @Log(title = "查铺记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yhInspectionService.deleteYhInspectionByIds(ids));
    }
}
